<?php

class Application_Model_UserMapper
{

    
    public function setDbTable($dbTable)
    {
        if (is_string($dbTable))
        {
            $dbTable = new $dbTable();
        }
        if (!$dbTable instanceof Zend_Db_Table_Abstract)
        {
            throw new Exception('Invalid table data gateway provided');
        }
        $this->_dbTable = $dbTable;
        return $this;
    }

    public function getDbTable()
    {
        if (null === $this->_dbTable)
        {
            $this->setDbTable('Application_Model_DbTable_User');
        }
        return $this->_dbTable;
    }

    public function fetchAll()
    {
        $records = $this->getDbTable()->fetchAll();

        $return = array();
        foreach($records as $item)
        {
            print_r($item);die();
            $user = new Application_Model_User();
        }
    }

    public function add(Application_Model_User $user)
    {
        $data['username'] = $user->getUsername();
        $data['password'] = $user->getPassword();
        $data['email'] = $user->getEmail();
        $data['balance'] = $user->getBalance();
        $data['joined'] = $user->getJoined();
        $data['last_ip'] =  $user->getLast_ip();
        $data['suspended'] = $user->getSuspended();
        $data['verified'] = $user->getVerified();
        $data['online'] = $user->getOnline();
        $data['firstname'] = $user->getFirstname();
        $data['lastname'] = $user->getLastname();
        $data['country'] = $user->getCountry();
        $data['streetaddress'] = $user->getStreetaddress();
        $data['reffered_by'] = $user->getReferred_by();

        $return = $this->getDbTable()->insert($data);
        return $return;
    }

}

